const app = getApp();
Page({

  data: {
    currentIndex: 1,
    pageSize: 10,
    secondHands: []
  },

  onLoad: function () {
    getSecondHands(this);
  },

  onReady: function () {

  },

  onShow: function () {
    this.onLoad();
  },


  //下拉到底触发刷新函数
  onReachBottom: function () {
    this.setData({
      pageSize: this.data.pageSize + 10
    });
    getMessages(this);
  },

  //下拉刷新
  onPullDownRefresh: function () {
    this.setData({
      currentIndex: 1
    });
    getMessages(this);
  },


  //转跳到添加页面函数
  add: function () {
    wx.navigateTo({
      url: '../addSecondHand/addSecondHand',
    })
  },

  goToDetail: function (e) {
    wx.navigateTo({
      url: '../socialContactDetail/socialContactDetail?messageId=' + e.currentTarget.dataset.id,
    })
  }

})



const getSecondHands = function (_this) {
  wx.request({
    url: 'https://dorm.dormassistant.wang:8080/secondHand/queryAll',
    method: "GET",
    data: {
      currIndex: _this.data.currentIndex,
      pageSize: _this.data.pageSize
    },
    success: function (res) {
      console.log(res.data);
      _this.setData({
        secondHands : res.data.secondHands
      });
      
    },
    fail: function (res) {
      wx.showToast({
        title: "网络故障",
        icon: '',
        duration: 2000
      });
    }
  });
}
